﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using ExtAspNet;
using Ylh.BLL;
using System.Data;

public partial class Module_StaffManger_AddRole : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnCancel.OnClientClick = ActiveWindow.GetHidePostBackReference();
        if (!IsPostBack)
        {
            if (Request.QueryString["RoleID"] != null)
            {
                FileRoleInfo(Request.QueryString["RoleID"].ToString());
            }
        }


    }

    private void FileRoleInfo(string RoleID)
    {
        RoleBLL robll = new RoleBLL(DbConnectionStr);
        DataTable dt = robll.GetRoleInFo(Convert.ToDecimal(RoleID));

        RoleName.Text = dt.Rows[0]["RoleName"].ToString();
        this.RoleID.Text = dt.Rows[0]["RoleID"].ToString();
        Remark.Text = dt.Rows[0]["Remark"] != null ? dt.Rows[0]["Remark"].ToString() : "";

        ProtectCount.Text = dt.Rows[0]["ProtectCount"].ToString();
    }

    protected void btnComfirm_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(RoleName.Text.Trim()))
        {
            Alert.Show("角色名称不能为空");
            return;
        }

        if (string .IsNullOrEmpty(ProtectCount.Text.Trim()))
        {

            Alert.Show("保护限制人数不能为空");
            return;
        }



        RoleBLL robll = new RoleBLL(DbConnectionStr);

        if (string.IsNullOrEmpty(RoleID.Text.Trim()))
        {
            //if (robll.IsExistsRole(RoleName.Text.Trim()))
            //{
            //    Alert.Show("角色名称已经存在,请重新输入");
            //    return;
            //}
            RoleID.Text = robll.InsertRole(RoleName.Text.Trim(), Remark.Text.Trim(), StaffName, ProtectCount.Text.Trim()).ToString();
            if (!string.IsNullOrEmpty(RoleID.Text))
            {
                Alert.Show("角色信息创建成功");
              
            }
            else Alert.Show("角色信息没有创建成功,请联系管理员");

        }
        else
        {
            if (robll.UpdateRole(RoleName.Text.Trim(),Remark.Text.Trim(), Convert.ToDecimal(RoleID.Text), ProtectCount.Text.Trim()))
            {
                Alert.Show("角色信息修改成功");
                FileRoleInfo(RoleID.Text);
            }
            else Alert.Show("角色信息没有修改成功,请联系管理员");
        }
    }
    protected void BtnAdd_Click(object sender, EventArgs e)
    {

        RoleName.Text = Remark.Text = RoleID.Text = string.Empty;
    }
}